package com.yztc.yidoutang.fragment.pic_fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.yztc.yidoutang.R;
import com.yztc.yidoutang.adapter.PicRecyclerAdapter;
import com.yztc.yidoutang.base.BaseFragment;
import com.yztc.yidoutang.bean.TuPianBean;
import com.yztc.yidoutang.utils.SpacesItemDecoration;

/**
 * Created by My on 2016/10/18.
 */

public class PicFragment extends Fragment implements PicContract.View {
    private String queryWords="";
    private PicContract.Presenter presenter=new PicPresenter(this);
    private RecyclerView mRecyclerView;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_pic, null);
        mRecyclerView= (RecyclerView) view.findViewById(R.id.pic_rv);
        initView();
        return view;
    }

    public void initView() {
        Bundle bundle=getArguments();
        queryWords=bundle.getString("queryWords");
        Log.i("tag",queryWords);
        mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2,
                StaggeredGridLayoutManager.VERTICAL));
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
        SpacesItemDecoration decoration = new SpacesItemDecoration(10);
        mRecyclerView.addItemDecoration(decoration);
        getPicData();
    }

    @Override
    public void getPicData() {
        presenter.getPicData(queryWords);
    }

    @Override
    public void GetPicDataSuccess(TuPianBean tuPianBean) {
        PicRecyclerAdapter adapter=new PicRecyclerAdapter(getActivity(),tuPianBean.getData().getPics());
        mRecyclerView.setAdapter(adapter);
    }

    @Override
    public void GetPicDataFail(String msg) {

    }
}
